<!--计划管理---1-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="小区名称" prop="premiseName">
        <el-input
          v-model="queryParams.premiseName"
          placeholder="请输入小区名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租客姓名" prop="tenantName">
        <el-input
          v-model="queryParams.tenantName"
          placeholder="请输入租客姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款单号" prop="receiptOrderNo">
        <el-input
          v-model="queryParams.receiptOrderNo"
          placeholder="请输入收款单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款状态" prop="skStatus">
        <el-select v-model="queryParams.skStatus"  clearable placeholder="请选择">
          <el-option

            v-for="item in skStatuss"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
        <el-form-item label="账单类型" prop="billType">
          <el-select v-model="queryParams.billType" clearable placeholder="请选择">
            <el-option
              v-for="item in billTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item label="合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应收日期" prop="collectionDate">
        <el-date-picker clearable
                        v-model="queryParams.startCollectionDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择预定收款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="collectionDate">
        <el-date-picker clearable
                        v-model="queryParams.endCollectionDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择预定收款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="实收日期" prop="realCollectionDate">
        <el-date-picker clearable
                        v-model="queryParams.startRealCollectionDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际收款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="realCollectionDate">
        <el-date-picker clearable
                        v-model="queryParams.endRealCollectionDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际收款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['property:receipt:export']"
        >导出</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="sendMQ"
          v-hasPermi="['property:receipt:export']"
        >发送MQ消息</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-tabs type="border-card"  @tab-click="operationTypeChange">
      <el-tab-pane label="房屋收款计划" >
        <el-table v-loading="loading" :data="receiptList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="租房合同号" align="center" width="165"  prop="contractNo" />
          <el-table-column label="收款单号" align="center" width="165"   prop="receiptOrderNo" />
          <el-table-column label="承租房间(使用房源名称)" align="center" prop="roomName" />
          <el-table-column label="租客姓名(面向业主收款时，为空)" align="center" prop="tenantName" />
          <el-table-column label="小区名称(使用楼盘名)" align="center" prop="premiseName" />
          <el-table-column label="支付金额" align="center" prop="paymentAmount" />
          <el-table-column label="账单" align="center" prop="receiptNumber" >
            <template slot-scope="scope">
              第{{scope.row.receiptNumber}}期
            </template>
          </el-table-column>
          <el-table-column label="收款状态" align="center" prop="skStatus" >
            <template slot-scope="scope">
  <!--            1:未收款 2：已收款 3：已中止  4：已冻结-->
              <span v-if="scope.row.skStatus==1">未收款</span>
              <span v-if="scope.row.skStatus==2">已收款</span>
              <span v-if="scope.row.skStatus==3">已中止</span>
              <span v-if="scope.row.skStatus==4">已冻结</span>
            </template>
          </el-table-column>
          <el-table-column label="账单类型" align="center" prop="billType" >
            <template slot-scope="scope">
<!--          1：分期变更2：租约保理变更3：退租变更 4：普通账单-->
            <span v-if="scope.row.billType==1">分期变更2</span>
            <span v-if="scope.row.billType==2">租约保理变更3</span>
            <span v-if="scope.row.billType==3">退租变更</span>
            <span v-if="scope.row.billType==4">普通账单</span>
            </template>
          </el-table-column>
          <el-table-column label="应收日期" align="center" prop="collectionDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.collectionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="实收日期" align="center" prop="realCollectionDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.realCollectionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="支付方式" align="center" prop="payMethod" />
          <el-table-column label="操作人" align="center" prop="operationUser" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="租务收款计划" >
        <el-table v-loading="loading" :data="receiptList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="租房合同号" align="center" width="165"  prop="contractNo" />
          <el-table-column label="收款单号" align="center" width="165"   prop="receiptOrderNo" />
          <el-table-column label="承租房间(使用房源名称)" align="center" prop="roomName" />
          <el-table-column label="租客姓名(面向业主收款时，为空)" align="center" prop="tenantName" />
          <el-table-column label="小区名称(使用楼盘名)" align="center" prop="premiseName" />
          <el-table-column label="支付金额" align="center" prop="paymentAmount" />
          <el-table-column label="账单" align="center" prop="receiptNumber" >
            <template slot-scope="scope">
              第{{scope.row.receiptNumber}}期
            </template>
          </el-table-column>
          <el-table-column label="收款状态" align="center" prop="skStatus" >
            <template slot-scope="scope">
              <!--            1:未收款 2：已收款 3：已中止  4：已冻结-->
              <span v-if="scope.row.skStatus==1">未收款</span>
              <span v-if="scope.row.skStatus==2">已收款</span>
              <span v-if="scope.row.skStatus==3">已中止</span>
              <span v-if="scope.row.skStatus==4">已冻结</span>
            </template>
          </el-table-column>
          <el-table-column label="账单类型" align="center" prop="billType" >
            <template slot-scope="scope">
              <!--          1：分期变更2：租约保理变更3：退租变更 4：普通账单-->
              <span v-if="scope.row.billType==1">分期变更2</span>
              <span v-if="scope.row.billType==2">租约保理变更3</span>
              <span v-if="scope.row.billType==3">退租变更</span>
              <span v-if="scope.row.billType==4">普通账单</span>
            </template>
          </el-table-column>
          <el-table-column label="应收日期" align="center" prop="collectionDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.collectionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="实收日期" align="center" prop="realCollectionDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.realCollectionDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="支付方式" align="center" prop="payMethod" />
          <el-table-column label="操作人" align="center" prop="operationUser" />
        </el-table>
      </el-tab-pane>
    </el-tabs>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listReceipt,
  getReceipt,
  sendRocketMQ,
  delReceipt,
  addReceipt,
  updateReceipt,
} from "@/api/property/receipt";

export default {
  name: "Receipt",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收款计划管理1表格数据
      receiptList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        receiptOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        receiptType: null,
        skStatus: null,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withReceiptPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        collectionDate: null,
        realCollectionDate: null,
        receiptNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      //收款类型
      skStatuss:[
        //:未收款 2：已收款 3：已中止  4：已冻结
        {value: 1, label: '未收款'},
        {value: 2, label: '已收款'},
        {value: 3, label: '已中止'},
        {value: 4, label: '已冻结'},
      ],
      //账单类型
      billTypes:[
        //:1：分期变更2：租约保理变更3：退租变更4：普通账单
        {value: 1, label: '分期变更'},
        {value: 2, label: '租约保理变更'},
        {value: 3, label: '退租变更'},
        {value: 4, label: '普通账单'},
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        receiptOrderNo: [
          { required: true, message: "收款单号不能为空", trigger: "blur" }
        ],
        businessId: [
          { required: true, message: "商户ID不能为空", trigger: "blur" }
        ],
        contractId: [
          { required: true, message: "合同ID不能为空", trigger: "blur" }
        ],
        contractNo: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
        contractType: [
          { required: true, message: "合同类型,1：收房合同，2：出房合同不能为空", trigger: "change" }
        ],
        premiseId: [
          { required: true, message: "楼盘ID不能为空", trigger: "blur" }
        ],
        premiseName: [
          { required: true, message: "小区(使用楼盘名)不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识,0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    sendMQ(){
      sendRocketMQ().then(res=>{
        this.$message.success("发送成功");
      })
    },
    /** 查询收款计划管理1列表 */
    getList() {
      this.loading = true;
      listReceipt(this.queryParams).then(response => {
        this.receiptList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        receiptOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        receiptType: null,
        skStatus: null,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withReceiptPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        collectionDate: null,
        realCollectionDate: null,
        receiptNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** tags表格切换 */
    operationTypeChange(tab, event) {
      if (tab.index == 0) {
        this.queryParams.contractType = 1;
      } else if (tab.index == 1) {
        this.queryParams.contractType = 2;
      }
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('property/receipt/export', {
        ...this.queryParams
      }, `receipt_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
